package com.glx.test.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class JsonUtils {
    
    // 使用jackson 构建安全标准请求体，底层已转义
    public static String buildJsonBody(String text,String information) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        ObjectNode rootNode = objectMapper.createObjectNode();
        rootNode.put("model", "deepseek-chat");

        ArrayNode messages = rootNode.putArray("messages");
        ObjectNode message = messages.addObject();
        message.put("role", "user");
        message.put("content", text + information);

        //判断是对话还是翻译，因为对话直接传输用户问题，翻译需要自己把控提问技巧
        if (information.isEmpty()){
            rootNode.put("stream", true);
        }
        return objectMapper.writeValueAsString(rootNode);
    }


}
